package com.liu.test.singleton;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by shi860715@126.com
 * Date 2021/7/8 11:22
 * 饿汉模式 static
 * 1 构造器私有化
 * 2 自行创建
 * 3 向外提供整个实例
 * 4 强调整个是一个单例，我们可以使用final 修饰
 */
public class Singleton3 {

    public static  final Singleton3 INSTANCE;

    private String info;

    static {

        Properties properties = new Properties();
        try {
            properties.load(Singleton3.class.getClassLoader().getResourceAsStream("test.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        INSTANCE =new Singleton3(properties.getProperty("info"));
    }

    private Singleton3(String info){
        this.info =info;

    }


    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    @Override
    public String toString() {
        return "Singleton3{" +
                "info='" + info + '\'' +
                '}';
    }
}
